package com.hyh.admin.domain.resources.vo;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.hyh.ad.common.core.domain.BaseEntity;
import com.hyh.admin.domain.resources.Resources;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/*
 * resources与es的操作类
 */
@Data
public class ResourcesVo extends BaseEntity {
    /**
     * 资源id
     */
    @ApiModelProperty(value = "资源id")
    private Long id;

    /**
     * 父类id
     */
    private Long parentId;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 资源标题
     */
    private String title;

    /**
     * 资源描述
     */
    private String description;

    /**
     * 资源路径
     */
    private String url;

    /**
     * 资源时长
     */
    private String duration;

    /**
     * 资源分类id
     */
    private Long categoryId;

    /**
     * 资源热度
     */
    private String hotDegree;

    /**
     * 资源类型
     */
    private String category;

    /**
     * 收藏量
     */
    private String collectCount;

    /**
     * 下载量
     */
    private String downloadCount;

    /**
     * 点赞量
     */
    private String loveCount;

    /**
     * 分享量
     */
    private String shareCount;

    /**
     * 标签属性
     */
    private String tags;

    /**
     * 资源第几集
     */
    private String episodeNumber;

    /**
     * 资源状态
     */
    private String status;

    /**
     * 是否推荐资源
     */
    private Boolean isFeatured;

    /**
     * 资源评分
     */
    private String rating;

    /**
     * 评论数
     */
    private Integer reviewCount;

    /**
     * 资源来源
     */
    private String source;

    /**
     * 封面图片url
     */
    private String coverImage;

    /**
     * 资源文件大小
     */
    private String fileSize;

    /**
     * 资源格式
     */
    private String format;


    /*
     * 自动补全属性
     */
    private List<String> suggestion;


    /*
     *创建时间
     */
    private Date createTime;

    /*
     * 更新时间
     */
    private Date updateTime;
    /*
     * 类型转换
     */
    public ResourcesVo(ResourcesCategoryVo resources) {
        this.id = resources.getId();
        this.title = resources.getTitle();
        this.description = resources.getDescription();
        this.categoryId = resources.getCategoryId();
        this.hotDegree = resources.getHotDegree();
        this.coverImage = resources.getCoverImage();
        this.category = resources.getCategory();
        this.collectCount = resources.getCollectCount();
        this.loveCount = resources.getLoveCount();
        this.reviewCount = resources.getReviewCount();
        this.shareCount = resources.getShareCount();
        this.downloadCount = resources.getDownloadCount();
        this.isFeatured = resources.getIsFeatured();
        this.createTime = resources.getCreateTime();
        this.updateTime = resources.getUpdateTime();

        // 确保 suggestion 已初始化
        if (this.suggestion == null) {
            this.suggestion = new ArrayList<>();
        }

        // 只有 category 不为空时，才加入到 suggestion
        if (resources.getCategory() != null) {
            this.suggestion.add(resources.getCategory());
        }

        if (resources.getTags() != null) {
            this.tags = resources.getTags();
            this.suggestion.add(resources.getTags());
        }

    }
}
